<?php
namespace app\admin\controller;

use app\admin\service\Menus;
use app\admin\service\PermissionCategory;
use think\Request;

class Index extends Controllers
{
    public function index(Menus $menusService, Request $request, PermissionCategory $permissionCategory)
    {
        $userInfo = $request->userInfo;
        $inCategory = [];
        if ( $userInfo['type'] != 1 ) {
            $inCategory = $permissionCategory->getPermissionCategoryByUserInfo($userInfo);
        }
        $menu = $menusService->getMenus( $inCategory );
        $config = config('field.admin');
        $prefix = config('database.prefix');
        $this->assign([
            'menu' => $menu,
            'typeName' => $config['type'][$userInfo['type']],
            'inCategory' => $inCategory,
            'userInfo' => $userInfo,
            'skin' => $config['skin'],
            'prefix' => $prefix
        ]);

        return view('admin@index/index');
    }

    public function welcome(Request $request)
    {
        $userInfo = $request->userInfo;
        $this->assign([
            'userInfo' =>  $userInfo
        ]);
        return view('admin@index/welcome');
    }

    public function getIcon()
    {
        $icon = config('menus.icon');
        return success(['icon'=>$icon]);
    }

}
